package com.smart_campus.teg.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.smart_campus.sys.common.DataGridView;
import com.smart_campus.teg.domain.Course;
import com.smart_campus.teg.vo.ExamVo;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.smart_campus.teg.mapper.ExamMapper;
import com.smart_campus.teg.domain.Exam;
import com.smart_campus.teg.service.ExamService;

import java.util.List;

/**
*   @aytgor 陈鹏
*   @date 2020/7/1 15:16
*
*/
@Service
public class ExamServiceImpl implements ExamService{

    @Resource
    private ExamMapper examMapper;

    //@CacheEvict 删除的注解通过对象id在redis中删除数据
    @CacheEvict(cacheNames = "com.smart_campus.teg.service.impl.ExamServiceImpl",key = "#examId")
    @Override
    public int deleteByPrimaryKey(Integer examId) {
        return examMapper.deleteByPrimaryKey(examId);
    }

    //@CachePut 要返回对象 添加通过reids主键回填的id来在redis创建对应id的对象数据
    @CachePut(cacheNames = "com.smart_campus.teg.service.impl.ExamServiceImpl",key = "#result.examId")
    @Override
    public Exam insert(Exam record) {
        examMapper.insert(record);
        return record;
    }

    //@CachePut 要返回对象 添加通过reids主键回填的id来在redis创建对应id的对象数据
    @CachePut(cacheNames = "com.smart_campus.teg.service.impl.ExamServiceImpl",key = "#result.examId")
    @Override
    public Exam insertSelective(Exam record) {
        examMapper.insertSelective(record);
        return record;
    }

    //@Cacheable 返回对象 通过对象id在redis中创建对象保存,方便下次使用
    @Cacheable(cacheNames ="com.smart_campus.teg.service.impl.ExamServiceImpl",key = "#examId")
    @Override
    public Exam selectByPrimaryKey(Integer examId) {
        return examMapper.selectByPrimaryKey(examId);
    }

    //@CachePut 要返回对象 修改通过返回的对象id来在redis修改对象数据
    @CachePut(cacheNames ="com.smart_campus.teg.service.impl.ExamServiceImpl",key = "#result.examId")
    @Override
    public Exam updateByPrimaryKeySelective(Exam record) {
        examMapper.updateByPrimaryKeySelective(record);
        return record;
    }

    //@CachePut 要返回对象 修改通过返回的对象id来在redis修改对象数据
    @CachePut(cacheNames ="com.smart_campus.teg.service.impl.ExamServiceImpl",key = "#result.examId")
    @Override
    public Exam updateByPrimaryKey(Exam record) {
        examMapper.updateByPrimaryKey(record);
        return record;
    }

    @Override
    public DataGridView getExamList(ExamVo examVo) {
        Page<Object> page = PageHelper.startPage(examVo.getPage(),examVo.getLimit());//分页数据格式
        List<ExamVo> list =examMapper.getExamList(examVo);//返回的全部数据
        return new DataGridView(page.getTotal(),list);
    }

}
